package cn.zymall.goods.controller;

import cn.zymall.common.controller.crud.BaseController;
import cn.zymall.common.model.MerchantSpu;
import cn.zymall.goods.service.MerchantSpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lxh
 * @Description TODO
 * @date 2020/8/24 19:58
 * @Classname MerchantSpuController
 **/
@RestController
@RequestMapping("/merchantSpu")
public class MerchantSpuController extends BaseController<MerchantSpuService, MerchantSpu> {

	@Autowired
	private MerchantSpuService merchantSpuService;

	/**
	 * 根据id查询所有的店铺商品分类
	 * @return
	 */
	@GetMapping("/findAll/{id}")
	public List<MerchantSpu> findAll(@PathVariable(name = "id") Integer id){
		return merchantSpuService.findAll(id);
	}


	/**
	 * 添加店铺商品分类
	 * @param merchantSpu
	 */
	@PostMapping("/add")
	public void add(MerchantSpu merchantSpu){
		merchantSpuService.add(merchantSpu);
	}


	/**
	 * 修改店铺商品分类
	 * @param merchantSpu
	 */
	@PostMapping("/amend")
	public void amend(MerchantSpu merchantSpu){
		merchantSpuService.amend(merchantSpu);
	}


	/**
	 * 根据店铺商品分类id计算商品总数
	 * @param id
	 */
	@GetMapping("/countSpu/{id}")
	public Integer countSpu(@PathVariable(name = "id") Integer id){
		return merchantSpuService.countSpu(id);
	}

	/**
	 * 根据id删除店铺
	 * @param id
	 */
	@DeleteMapping("/del/{id}")
	public void del(@PathVariable(name = "id") Integer id){
		merchantSpuService.del(id);
	}
}
